package cz.muni.fi.pb162.project.geometry;


/**
 * Class for creating a regular measurable and solid polynom
 * 
 * @author Martin Pasko
 * @version 22_10_2012
 */
public class GeneralRegularPolygon implements RegularPolygon, Colored
{
    private int numEdges;
    private double edgeLength;
    private Vertex2D center;
    private Color color = Color.WHITE;
    
/**
 * Creates a regular measurable and solid polynom
 * @param center center of the polynom
 * @param numEdges number of edges
 * @param edgeLength length of the edge
 */    

    public GeneralRegularPolygon(Vertex2D center, int numEdges, double edgeLength) {
        this.center = center;
        this.numEdges = numEdges;
        this.edgeLength = edgeLength;
    }
       
    public int getNumEdges() {
        return numEdges;
    }
    
    public double getEdgeLength() {
        return edgeLength;
    }
    
    public Vertex2D getCenter() {
        return center;
    }

    public double getRadius() {
        return getEdgeLength()/(2*Math.sin(Math.PI/numEdges));
    }
    
    public Color getColor() {
        return color;
    }
    
    public void setColor(Color color) {
        this.color = color;
    }
    
/**
 * Returns width of a nearest rectangle
 * @return width of a nearest rectangle around the regular polynom
*/

    public double getWidth() {
        return 2*getRadius();
    }

/**
 * Returns height of a nearest rectangle
 * @return height of a nearest rectangle around the regular polynom
*/

    public double getHeight() {
        return 2*getRadius();
    }

/**
 * Returns perimeter of the regular  polynom
 * @return perimeter of the regular polynom
*/

    public double getLength() {
        return getNumEdges()*getEdgeLength();
    }

/**
 * Returns area of the regular polynom.
 * @return area of the regular polynom
*/

    public double getArea() {
        return 0.5*getNumEdges()*Math.pow(getRadius(), 2)*Math.sin((2*Math.PI)/getNumEdges());
    }

/**
* toString method
* @return String enumerating center parameters of the polygon and the length, number of its edges and its color
*/

    @Override
    public String toString() {
        return ""+getNumEdges()+"-gon: center="+center+", edge length="+getEdgeLength()+", color="+color;
    }
}
